using System.Collections.Generic;
using UnityEngine;

public class LeaderBoardScrollUI : MonoBehaviour
{
	[SerializeField]
	private PanelLeaderBoardUI.TypeLeaderBoard typeLeaderBoard;

	[SerializeField]
	private GameObject ohterPlacePlayer;

	[SerializeField]
	private List<GameObject> placeNumberPlayer;

	[SerializeField]
	private UIGrid grid;

	[SerializeField]
	private UIScrollView scroll;

	[SerializeField]
	private GameObject myPlace;

	private bool _init;

	private void OnEnable()
	{
		if (!_init)
		{
			InitButtons();
		}
	}

	private void InitButtons()
	{
		List<LeaderInfo> topByTypeLeaderBoard = LeaderBoardParser.GetInstance().GetTopByTypeLeaderBoard(typeLeaderBoard);
		foreach (LeaderInfo item in topByTypeLeaderBoard)
		{
			GameObject gameObject = ((item.place <= 0 || item.place > placeNumberPlayer.Count) ? Object.Instantiate(ohterPlacePlayer) : Object.Instantiate(placeNumberPlayer[item.place - 1]));
			PlayerInLeaderBoardPanel component = gameObject.GetComponent<PlayerInLeaderBoardPanel>();
			gameObject.SetActive(true);
			gameObject.transform.SetParent(grid.transform);
			gameObject.transform.localScale = Vector3.one;
			component.Init(item);
			if (typeLeaderBoard == PanelLeaderBoardUI.TypeLeaderBoard.TopLeague)
			{
				component.HideLeagueLabel();
			}
			if ((bool)myPlace && item.me)
			{
				MyPlayerInLeaderBoardPanel component2 = myPlace.GetComponent<MyPlayerInLeaderBoardPanel>();
				component2.PlaceInGrid = gameObject;
				component2.CenterOnChaild = grid.GetComponent<UICenterOnChild>();
				component2.Scroll = scroll;
				component2.Init(item);
				if (typeLeaderBoard == PanelLeaderBoardUI.TypeLeaderBoard.TopLeague)
				{
					component2.HideLeagueLabel();
				}
				myPlace.SetActive(!scroll.GetComponent<UIPanel>().IsVisible(gameObject.GetComponent<UIWidget>()));
			}
		}
		grid.repositionNow = true;
		_init = true;
	}
}
